]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
appMenu: Delay window sections update when selecting window
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 12 Aug 2021 00:16:59 +0000 (02:16 +0200)
committerMarge Bot <marge-bot@gnome.org>
Mon, 16 Aug 2021 21:28:22 +0000 (21:28 +0000)
App windows are ordered by recency, so a focus change (correctly)
triggers the ::window-changed signal. If we rebuild the section
immediately in response, the activating item will be destroyed
before the menu's ::activate handler, with the result that the
menu remains open.

Defer the section update in that case to allow the menu to process
the ::activate signal first.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1948>

js/ui/appMenu.js

index 42c92a42226239c550f1910c29b8c4c07e235455..a795e8e6166147e19d2a2c9b49b3062080cd6818 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 /* exported AppMenu */
-const { Gio, GLib, Shell, St } = imports.gi;
+const { Gio, GLib, Meta, Shell, St } = imports.gi;
 
 const PopupMenu = imports.ui.popupMenu;
 const Main = imports.ui.main;
@@ -18,6 +18,7 @@ var AppMenu = class AppMenu extends PopupMenu.PopupMenu {
         this._appSystem = Shell.AppSystem.get_default();
 
         this._windowsChangedId = 0;
+        this._updateWindowsLaterId = 0;
 
         /* Translators: This is the heading of a list of open windows */
         this._openWindowsHeader = new PopupMenu.PopupSeparatorMenuItem(_('Open Windows'));
@@ -103,9 +104,8 @@ var AppMenu = class AppMenu extends PopupMenu.PopupMenu {
         this._app = app;
 
         if (app) {
-            this._windowsChangedId = app.connect('windows-changed', () => {
-                this._updateWindowsSection();
-            });
+            this._windowsChangedId = app.connect('windows-changed',
+                () => this._queueUpdateWindowsSection());
         }
 
         this._updateWindowsSection();
@@ -125,7 +125,22 @@ var AppMenu = class AppMenu extends PopupMenu.PopupMenu {
             app && app.can_open_new_window() && !actions.includes('new-window');
     }
 
+    _queueUpdateWindowsSection() {
+        if (this._updateWindowsLaterId)
+            return;
+
+        this._updateWindowsLaterId = Meta.later_add(
+            Meta.LaterType.BEFORE_REDRAW, () => {
+                this._updateWindowsSection();
+                return GLib.SOURCE_REMOVE;
+            });
+    }
+
     _updateWindowsSection() {
+        if (this._updateWindowsLaterId)
+            Meta.later_remove(this._updateWindowsLaterId);
+        this._updateWindowsLaterId = 0;
+
         this._windowSection.removeAll();
         this._openWindowsHeader.hide();